Automatic Clipart Viewer with Optional Music

Home

View 3D

Math for LB

Using the Modem

Functions

Subroutines

Hall of Fame

API Corner

Tip Corner - RUN

Clipart Viewer

User Design Graphics

Sort by Surnames

Many Textboxes

Newsletter help

Index


This displays a variety of Clipart images in succession, using the full screen, in conjunction with music played in the background provided by either MP3 or Midi files. It may find use in waiting rooms. It has been tested for over 30 minutes, using my system with a 2.6 Gig CPU and 512 Mb RAM. The program uses many routines and image323.dll kindly provided by Alyce on her web site. I am also grateful for Stefan Pendl at megabit@t-online.at for showing me how to adapt Alyce's routines, to enable full screen displays to be achieved with her dlll.

The first problem is to automatically select all the required files in any directory. We should not expect the user to copy all the clipart or music files into special directories, though he or she may prefer to do so. You will see the [create] routine based on DIR.BAS supplied with LB, creates the sound$ and clip$ arrays based ext$ set as selected from the filedialogs. If the user enters ALL, instead of selecting a sample image file, then all valid files in that directory will be selected. This is controlled by READing the valid images list in the [start] section each time the program selects a new file. So it does not matter if there are any other types of files in the directory chosen, or even if sub directories are present, they will be ignored. The limit of 500 for each array was chosen in case systems using smaller RAM cannot cope with larger arrays, but it should be safe to increase it with larger RAM.

The next problem is to ensure the MP3 or MID players are allowed to constantly check if the relevant music file has finished playing, to call the next to be played in [music]. This is achieved through the [loop] routine, but we have the problem of timing how long each image is displayed as set by SHOW in seconds. decided by the user. You will see this is achieved by either inserting quick routines in [loop], such as printing the TIME$, or by going to a quick subroutine, to change the clipart image shown, when the SHOW period has elapsed.

Gordon Sweet


Demo:

' Auto Full Screen Clipart Viewer with optional music
' ADAPTED FROM :-
' scale bitmap to fill box by Alyce Watson, August 2003
' API functions from her LB Workshop and needs
' image323.dll also obtained from
' http://alycesrestaurant.com/
' Modifications kindly provided by
' Stefan Pendl megabit@t-online.at


    nomainwin
    WindowWidth = DisplayWidth : WindowHeight = DisplayHeight
    ux = 0 : uy = 0
    if DisplayWidth > 1000 then ux = 120 : uy = 90
    tl$ = "Graphic Files Viewer with Music."
    open "image323.dll" for dll as #im
    open tl$ for graphics_nf_nsb as #v
    dim dir$(10,3) : dim sound$(501) : dim clip$(501)
    #v "trapclose [quit]; down; fill 0 0 40"
    #v "cls; fill 100 200 255; backcolor 100 200 255"
    #v "color yellow; font arial 24 bold; place ";220+ux;" ";40+uy
    #v "\The Liberty BMP Show"
    #v "font arial 8 bold; color black; place ";280+ux;" ";80+uy
    #v "\by Gordon Sweet ver. 2.4 - October 2003"
    #v "font arial 12 bold; place ";170+ux;" ";130+uy
    #v "\Files JPG, JIF, GIF, BMP, DIB, RLE, TGA, or PCX accepted"
    #v "\\When prompted find a Directory containing Graphics files, then"
    #v "\select any file by EXT, and all with same EXT will be selected."
    #v "\Alternatively if you enter ALL, then all valid files will be shown."
    #v "\\Next select sample MID or MP3 files for background music if"
    #v "\required, and all in that directory will be played in turn."
    #v "color blue; backcolor lightgray; place ";170+ux;" ";280+uy
    #v "flush" : play = 0 :  pic = 0 : setg = 0 : mext$ = "" : all = 0
    DefaultDir$ = left$(DefaultDir$,2)+"\"
    swide=DisplayWidth   'desired image width
    shigh=DisplayHeight   'desired image height
    DefaultDir$ = left$(DefaultDir$,2)+"\"
    hW=hwnd(#v)   'graphicbox handle
    x=0:y=0 'placement for bmps
    DefaultDir$ = left$(DefaultDir$,2)+"\"

[box3]
    tx$ = "Minimun display of Image is 5 seconds. Music is optional"
    UpperLeftX = 200+ux : UpperLeftY = 400+uy
    WindowWidth = 400: WindowHeight = 140
    statictext #opts, "Image Seconds", 40, 10, 80, 30
    statictext #opts, tx$, 20, 80, 380, 30
    textbox #opts.tbox1, 58, 40, 30, 25
    button #opts, "Select Images", [pickpicts], UL, 120, 40, 80, 25
    button #opts, "Select Music", [pickmusic], UL, 220, 40, 80, 25
    button #opts.default, "Accept", [passon], UL, 330, 40, 42, 25
    open "Select Clipart first" for dialog as #opts
    #opts "trapclose [quit]": box=1
    #opts.tbox1 "!setfocus"
    #opts.tbox1 "5"
[npass]
    playwave "YYY"   ' In case beep does not function
    mainH=hWnd(#opts) : gosub [boxhold]
    wait

[passon]
    #opts.tbox1, "!contents? A$" : show = val(A$)*1000
    if show < 5000 then notice "Invalid Duration!" : goto [npass]
    if pic = 0 then notice "NO Images selected!" : goto [npass]
    box=0 : close #opts
    if play = 1 then goto [music]
    if play = 0 then goto [start] else gosub [start]

[pickpicts]
    filter$ = "*.GIF;*.BMP;*.JPG;*.WMF;*.EMP;*.ICO"
    filedialog "Select sample image file or enter ALL", filter$, File$
    if File$ = "" then [quit]
    File$ = upper$(File$)
    if play = 0 and right$(File$,3) = "ALL" then all = 1
    if play = 1 then setg = 1
    play = 0 : gosub [create] : maxpic = x-1
    pic = 1
    goto [npass]

[pickmusic]
    if pic = 0 then notice "Select Clipart first." : goto [npass]
    pic$ ="*.mid;*.mp3"
    filedialog "Select any MIDi or MP3 file",pic$,File$
    if File$ = "" then [quit]
    play = 1 : gosub [create]
    setg = 1 : maxsnd = x-1
    tune = int(rnd(1)*maxsnd)+1
    goto [npass]

[start]
    bmp$ = cpath$+clip$(pic)
    bmp$=upper$(bmp$)
    iext$ = right$(bmp$,3)
    for img = 1 to maxpic
        accept = 0
        restore [types]    ' READ THE VALID IMAGES
        for t = 1 to 6
            read i$ 
            if iext$ = i$ then accept = 1
        if accept = 1 then exit for
    next t
    if accept = 0 then [done]

    picstart = time$("ms")

    hImage=LoadImageFile(hW,bmp$)
    if hImage=0 then
        notice "Function failed."
        cursor normal
        wait
    end if

    #v "discard; fill 0 0 40"
    if hDemo<>0 then unloadbmp "demo"

    hSize=ChangeSize(hImage,hW,swide,shigh)
    if hSize=0 then
        notice "Function failed."
        wait
    end if
    loadbmp "demo",hSize
    hDemo=hbmp("demo")
    #v "drawbmp demo 0 0 ; flush"
    call KeybdEvent VK.CONTROL, 0  'simulates Ctrl Press
    if play = 0 then gosub [halt]
[done]
    pic = pic + 1
    if pic > maxpic then pic = 1
    if play = 1 then return else goto [start]

[halt]
    tim=time$("ms")
    while time$("ms") < tim + show
        scan
    wend
    return

[create]
    File$ = upper$(File$)
    if play = 1 then mext$ = right$(File$,3)
    sFile$ = noPath$(File$)
    plen = len(File$)-len(sFile$)
    path$ = left$(File$,plen)
    if play = 0 then cpath$ = path$
    ext$ = "*."+right$(File$,3)
    if all = 1 and play = 0 then ext$ = "*.*"
    files path$, ext$, dir$()
    qtyFiles = val(dir$(0, 0))
    if qtyFiles > 500 then qtyFiles = 500
    qtySubDirs = val(dir$(0, 1))
    if qtyFiles = 0 and qtySubDirs = 0 then
        notice "EMPTY DIRECTORY!!"
        goto [quit]
    end if
    if qtyFiles = 0 then notice "NO FILES??" : goto [quit]
   'reformat the file information
    for x = 1 to qtyFiles
       dir$(x, 1) = right$("        " + dir$(x, 1), 9)
    next x
    sorting =int(rnd(1)*4)
    sort dir$(), qtyFiles, 1, sorting
    for x = 1 to qtyFiles
       if play = 0 then clip$(x) =  dir$(x, 0)
       if play = 1 then sound$(x) =  dir$(x, 0)
    next x
    return

[music]
    m$ = path$+sound$(tune)
    m$ = upper$(m$)
    gosub [mplay]
    tune = tune + 1
    if tune > maxsnd then tune = 1
    goto [music]

[mplay]
    open "winmm.dll" for dll as #mm
    mainH=hWnd(#v)
    if mext$="MP3" then goto [openmp3]

[openmid]
    m$=GetShortPathName$(m$)
    r$=mciSendString$("open "+m$+" type sequencer alias music")
    r$=mciSendString$("status music length")
    musiclength=val(r$)
    timer 100, [closeSong]
    musicOpen=1
    r$=mciSendString$("play music")
    goto [loop]

[openmp3]
    m$=GetShortPathName$(m$)
    r$=mciSendString$("open "+m$+" type MpegVideo alias music")
    r$=mciSendString$("status music length")
    mlength=val(r$)  'length of mp3
    timer 100, [closeMusic]
    musicOpen=1
    r$=mciSendString$("play music")
    goto [loop]

[closeMusic] 'check for finish
    r$=mciSendString$("status music position")
    if val(r$) picstart + show then gosub [start]
    #v "place 15 20"
    #v "\ ";time$();" "
    wait
    goto [loop]

[quit]
    if hDemo<>0 then unloadbmp "demo"
    if hImage<>0 then ok = DeleteObject(hImage)

    if play = 1 then gosub [quitm]
    if box = 1 then close #opts
    close #v : close #im : end

[types]
    data "GIF","JPG","BMP","ICO","EMF","WMF"
    end

Function GetShortPathName$(lPath$)
    lPath$=lPath$+Chr$(0)
    sPath$=Space$(256)
    lenPath=Len(sPath$)
    CallDLL #kernel32, "GetShortPathNameA",lPath$ As ptr,_
    sPath$ As ptr,lenPath As long,r As long
    GetShortPathName$=Left$(sPath$,r)
    End Function

[boxhold]
    open "user32" for dll as #user ' prevents losing box
        toTop=(-1 or 0)
        flags=_SWP_NOMOVE or _SWP_NOSIZE
    calldll #user,"SetWindowPos",mainH as ushort,toTop as short,_
    0 as short,0 as short,0 as short,0 as short,flags as ushort,_
    result as void
    close #user : return

function noPath$(t$)
    while instr(t$, "\")
    t$ = mid$(t$, 2)
    wend
    noPath$ = t$
    end function

sub KeybdEvent key, event
    calldll #user32, "keybd_event",_
        key as short,_
        0 as short,_
        event as long,_
        0 as long,_
        ret as void
    end sub


Function LoadImageFile(hWnd, file$)
    'load an image from file,
    'bmp, jpg, emf, wmf, ico
    'returns handle of memory bmp
    calldll #im, "LoadImageFile",hWnd as ulong,_
    file$ as ptr,LoadImageFile as ulong
    End Function


Function ChangeSize(hBmp,hWnd,nWidth,nHeight)
    'display in pixel size indicated
    calldll #im, "ChangeSize",hBmp as long,hWnd as long,_
    nWidth as long,nHeight as long,ChangeSize as ulong
    End Function

Function DeleteObject(hObject)
    CallDLL #gdi32,"DeleteObject",_
        hObject As Long,_    'handle of object
        DeleteObject As Long 'returns whatever
    End Function

Function mciSendString$(s$)
    'Buffer will contain a return string from
    'the function, if there is one.
    buffer$=space$(1024)+chr$(0)
    calldll #mm,"mciSendStringA",s$ as ptr,buffer$ as ptr,_
        1028 as long, 0 as long, r as long

    'truncate returned string at null character
    buffer$=left$(buffer$, instr(buffer$, chr$(0)) - 1)
        if r>0 then
            mciSendString$="error"
        else
            mciSendString$=buffer$
        end if
    End Function



Home

View 3D

Math for LB

Using the Modem

Functions

Subroutines

Hall of Fame

API Corner

Tip Corner - RUN

Clipart Viewer

User Design Graphics

Sort by Surnames

Many Textboxes

Newsletter help

Index